home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / TextViewHTMLString.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  2.2 KB  |  85 lines  |  [TEXT/CWIE]

  1. // TextViewHTMLString.java
  2. // By Ned Etcode
  3. // Copyright 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6. import netscape.util.*;
  7.  
  8. /** Instances of this class are used to store strings while converting HTML to
  9.   * strings and attributes.
  10.   * If you need to add some processing on strings, subclass TextViewHTMLString
  11.   * and use <b>TextView.setHTMLStringClass()</b> to tell TextView to use your
  12.   * subclass.
  13.   *
  14.   * @note 1.0 changes
  15.   */
  16. public class TextViewHTMLString extends TextViewHTMLElement {
  17.     /** Ivar to store the string for this instance */
  18.     String string;
  19.  
  20.  
  21.     /* Public methods */
  22.  
  23.  
  24.     /** Return the string for the component, given the context <b>context</b>
  25.      *  override this method if you want to perform some computation on the
  26.      *  string according to <b>context</b>. The default implementation is
  27.      *  equivalent to string()
  28.      */
  29.     public String string(Hashtable context) {
  30.         return string;
  31.     }
  32.  
  33.  
  34.     /** Return the string */
  35.     public String string() {
  36.         return string;
  37.     }
  38.  
  39.  
  40.     /* Private methods */
  41.  
  42.     void appendString(Hashtable context,FastStringBuffer fb) {
  43.       fb.append(string(context));
  44.     }
  45.  
  46.     /** Set the attributes for the string starting at index index */
  47.     void setAttributesStartingAt(int index, Hashtable attributes,TextView target,
  48.                                  Hashtable context) {
  49.       Range  r;
  50.       String s = string(context);
  51.       int length = s.length();
  52.       if( attributes != null  && length > 0) {
  53.           r = TextView.allocateRange(index,length);
  54.           target.addAttributesForRange( attributes , r );
  55.           TextView.recycleRange(r);
  56.       }
  57.     }
  58.     /** When parsing HTML, TextView will allocate an instance of the HTML
  59.       * string class for each strings and then call setString() on it.
  60.       * @private
  61.       */
  62.     public void setString(String aString) {
  63.         string = aString;
  64.     }
  65.  
  66.     /** @private */
  67.     public void setMarker(String aString) {
  68.     }
  69.  
  70.     /** @private */
  71.     public void setAttributes(String attributes) {
  72.     }
  73.  
  74.     /** @private */
  75.     public void setChildren(Object child[]) {
  76.     }
  77.  
  78.     public String toString() {
  79.         return string;
  80.     }
  81. }
  82.  
  83.  
  84.  
  85.